package com.stars.controller.system;
import com.stars.common.annotation.DictClass;
import com.stars.entity.system.SysAppEntity;
import com.stars.services.system.SysAppAccessServices;
import com.stars.services.system.SysAppConfigServices;
import com.stars.entity.dto.system.SysAppDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import com.stars.common.annotation.Log;
import com.stars.common.base.BaseMsg;
import com.stars.common.ObjectCopyUtils;
import com.stars.common.base.BaseConstant;
import com.stars.common.base.ResultMsg;
import com.stars.controller.BaseController;
import com.stars.common.enums.OperationType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.servlet.http.HttpServletRequest;
import com.stars.common.valid.AddView;
import com.stars.common.valid.UpdateView;
import com.github.pagehelper.PageInfo;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
/**
 * @Title: 系统app管理 mybatis dao
 * @author dj
 * @date 2019-10-12 18:11:37
 * @version V1.0
 *
 */
@Slf4j
@RestController
@RequestMapping("/sysAppCtl")
@Api(tags ="系统app管理")
public class SysAppCtl extends BaseController{
   @Autowired
   private SysAppAccessServices  sysAppAccessServicesImpl;
   @Autowired
   private SysAppConfigServices  sysAppConfigServicesImpl;

   /**
   *  分页查询
   * @param pageNum 起始页
   * @param pageSize 大小
   * @return 分页数据
   * @throws Exception
   */
   @GetMapping("/pageList")
   @ApiOperation(value = "系统app管理"+BaseMsg.MODULAR_PAGE,notes ="系统app管理"+ BaseMsg.MODULAR_PAGE)
   @Log(detail = "系统app管理"+ BaseMsg.MODULAR_PAGE,operationType = OperationType.SELECT)
   public PageInfo<SysAppDTO> pageSysAppList(Integer pageNum, Integer pageSize, SysAppDTO dto,HttpServletRequest request) throws Exception{
        setSystemCompany(dto,request);
        return sysAppAccessServicesImpl.pageList(pageNum,pageSize,dto);

   }

    /**
    * 保存
    * @param entityName
    * @return 成功失败
    * @throws Exception
    */
    @PostMapping(value = "/add")
    @ApiOperation(value = "系统app管理"+ BaseMsg.MODULAR_ADD,notes = "系统app管理"+BaseMsg.MODULAR_ADD)
    @Log(detail = "系统app管理"+BaseMsg.MODULAR_ADD,operationType = OperationType.INSERT)
    public ResultMsg addSysApp(@Validated({AddView.class}) SysAppEntity entityName,HttpServletRequest request) throws Exception{
        setAddCompany(entityName,request,null);
        return sysAppConfigServicesImpl.insertSelective(entityName);
    }
    /**
    * 更新
    * @param updateEntityDto
    * @return 成功失败
    * @throws Exception
    */
    @PostMapping(value = "/update")
    @ApiOperation(value = "系统app管理"+ BaseMsg.MODULAR_UPDATE,notes = "系统app管理"+ BaseMsg.MODULAR_ADD)
    @Log(detail = "系统app管理"+ BaseMsg.MODULAR_UPDATE,operationType = OperationType.UPDATE)
    public ResultMsg updateSysApp(@Validated({UpdateView.class}) SysAppEntity updateEntityDto,HttpServletRequest request) throws Exception{
        SysAppEntity entity = sysAppAccessServicesImpl.selectById(updateEntityDto.getId());
        ObjectCopyUtils.copyPropertiesIf(updateEntityDto,entity, BaseConstant.EXCLUDES_UPDATE_ORG);
        setUpdateBase(entity,request);
        return sysAppConfigServicesImpl.updateSelectiveById(entity);
    }

    /**
    * 根据id查询
    * @param id
    * @return 查询对象
    * @throws Exception
    */
    @GetMapping(value = "/findById")
    @ApiOperation(value = "系统app管理"+ BaseMsg.MODULAR_FIND_ID,notes = "系统app管理"+BaseMsg.MODULAR_FIND_ID)
    @Log(detail = "系统app管理"+ BaseMsg.MODULAR_FIND_ID,operationType = OperationType.SELECT)
    public ResultMsg findSysAppById(String id) throws Exception{
        SysAppEntity entityName = sysAppAccessServicesImpl.selectById(id);
         return ResultMsg.success(entityName);
    }

     /**
     * 删除
     * @param ids
     * @return 成功失败
     * @throws Exception
     */
     @PostMapping(value = "/delById")
     @ApiOperation(value = "系统app管理"+BaseMsg.MODULAR_DEL,notes ="系统app管理"+BaseMsg.MODULAR_DEL)
     @Log(detail ="系统app管理"+BaseMsg.MODULAR_DEL,operationType = OperationType.DELETE)
     public ResultMsg delSysAppById(String ids) throws Exception{
         return sysAppConfigServicesImpl.deleteById(ids);
     }

}